/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    
function applyFilter()
{    
    var counter =-1;
    var xmlhttp;
    var filter_id=0; //default
    //filter_id = document.getElementsByName("testdouble")[0].value;
    
    // check filter id
    // auto check filter
    // 0 - discretize
    // 1 - normalize
    // 2 - replace missing value
    // 3 - attributes selection
    var preprocess = document.getElementsByName("preprocess");
    var len = preprocess.length;
    var i =0;
    var chosen=0;
    for ( i=0; i< len ; i++){        
        if (preprocess[i].checked){
            chosen = i;            
        }        
    }
    filter_id = chosen;
    // end check filter id    
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
	
            if(xmlhttp.responseText.indexOf("false", 0)== -1){                
                document.getElementById("preprocessstatus").innerHTML="success ";
            }
            else {                
                document.getElementById("preprocessstatus").innerHTML="failed";                
            } 
        }else{
            if (counter ==0){
                document.getElementById("preprocessstatus").innerHTML="loading .";            
            }else if (counter ==1){                
                document.getElementById("preprocessstatus").innerHTML="loading ..";            
            }else if (counter==2){
                document.getElementById("preprocessstatus").innerHTML="loading ...";            
            }else {
                counter = -1;
                document.getElementById("preprocessstatus").innerHTML="loading";            
            }
                        
        }
        counter++;    
            
    }    
   
    
    var listattr = document.getElementsByName("attr");
    var stringoption="";
    for(i=0;i<listattr.length;++i){
        if (!listattr[i].checked){
            stringoption += (i+1);
            stringoption += ",";
        }
    }
    
    
    
    if (stringoption.length>0){         
        stringoption = stringoption.slice(0, stringoption.length-1);
        xmlhttp.open("GET","changeFilter.jsp?id="+filter_id+"&option="+stringoption,true);
    }else{        
        xmlhttp.open("GET","changeFilter.jsp?id="+filter_id,true);
        
    }
    
   
    
    xmlhttp.send();
}

function showDistributionDataGraph(){
    
    var xmlhttp;
    var attr_id=0; //default
                
    var showgraph= document.getElementsByName("show");
    var len = showgraph.length;
    var i =0;
    var chosen=0;
    for ( i=0; i< len ; i++){        
        if (showgraph[i].checked){
            chosen = i;            
        }        
    }
    attr_id = chosen;
    
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
	
            if(xmlhttp.responseText.indexOf("true", 0) != -1){
            //                alert(xmlhttp.responseText);
            }
            else {                
                alert("Error");
            } 
        }
                   
    }    
    xmlhttp.open("GET","showDistGraph.jsp?id="+attr_id,true);
    xmlhttp.send();
    
}


function doLearn(){    
    
    var testing_id=0; //default
                
    var testings= document.getElementsByName("testing");
    var len = testings.length;
    var i =0;
    var chosen=0;
    for ( i=0; i< len ; i++){        
        if (testings[i].checked){
            chosen = i;            
        }        
    }
    
    testing_id = chosen;    
    
    if (testing_id ==0){
        document.location.href= "doLearn.jsp?id="+testing_id;
        
    }else if (testing_id==1){
        document.location.href= "doLearn.jsp?id="+testing_id;        
    }else if (testing_id==2){
        var foldcsv = 0;    
        var folds = document.getElementsByName("folds");    
        
        if (typeof folds=== "undefined"){            
        }else{            
            foldcsv = folds[0].value;            
        
        }                
        document.location.href= "doLearn.jsp?id="+testing_id+"&fold="+foldcsv;
    
    }else if (testing_id==3){    
        var percentps =  0;    
        var percents = document.getElementsByName("percents");
        if (typeof percents=== "undefined"){            
        }else{            
            percentps = percents[0].value;            
        
        }        
        document.location.href= "doLearn.jsp?id="+testing_id+"&percent="+percentps;
    }        
}



